package org.ss.psci.dao;

import java.util.List;
import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.ss.psci.entity.PmContracts;
import org.ss.psci.entity.PmProjects;

/**
 * Data access object (DAO) for domain model class PmProjects.
 * 
 * @see org.ss.psci.entity.PmProjects
 * @author MyEclipse Persistence Tools
 */

public class PmProjectsDAO extends HibernateDaoSupport {
	private static final Log log = LogFactory.getLog(PmProjectsDAO.class);
	// property constants
	public static final String NAME = "name";
	public static final String COMPANY = "company";
	public static final String NUMBER = "number";
	public static final String START_TIME = "startTime";
	public static final String END_TIME = "endTime";
	public static final String PRICE = "price";
	public static final String COST = "cost";
	public static final String AREA = "area";
	public static final String MANAGER = "manager";
	public static final String MANAGE_DEP = "manageDep";
	public static final String DESIGN_DEP = "designDep";
	public static final String CONTROL_DEP = "controlDep";
	public static final String PROFIT = "profit";
	public static final String INTRODUCE = "introduce";
	public static final String REMARKS = "remarks";

	public static final String COMPANYID = "companyId";
	public static final String PROJECTID = "projectId";

	public List findByCompanyID(Object name) {
		return findByProperty(COMPANYID, name);
	}

	public List findByProjectID(Object name) {
		return findByProperty(PROJECTID, name);
	}

	public PmProjects copyEntity(PmProjects dest, PmProjects orig) {
		if (dest == null || orig == null) {
			return new PmProjects();
		}
		if (orig.getName() != null) {
			dest.setName(orig.getName());
		}
		if (orig.getCompany() != null) {
			dest.setCompany(orig.getCompany());
		}
		if (orig.getPrice() != null) {
			dest.setPrice(orig.getPrice());
		}
		if (orig.getProjectId() != null) {
			dest.setProjectId(orig.getProjectId());
		}
		if (orig.getCompanyId() != null) {
			dest.setCompanyId(orig.getCompanyId());
		}
		if (orig.getStartTime() != null) {
			dest.setStartTime(orig.getStartTime());
		}
		if (orig.getDesignDep() != null) {
			dest.setDesignDep(orig.getDesignDep());
		}
		if (orig.getControlDep() != null) {
			dest.setControlDep(orig.getControlDep());
		}
		if (orig.getManageDep() != null) {
			dest.setManageDep(orig.getManageDep());
		}
		if (orig.getManager() != null) {
			dest.setManager(orig.getManager());
		}
		if (orig.getEndTime() != null) {
			dest.setEndTime(orig.getEndTime());
		}
		if (orig.getCost() != null) {
			dest.setCost(orig.getCost());
		}
		if (orig.getArea() != null) {
			dest.setArea(orig.getArea());
		}
		if (orig.getProfit() != null) {
			dest.setProfit(orig.getProfit());
		}
		if (orig.getIntroduce() != null) {
			dest.setIntroduce(orig.getIntroduce());
		}
		if (orig.getRemarks() != null) {
			dest.setRemarks(orig.getRemarks());
		}
		return dest;
	}

	protected void initDao() {
		// do nothing
	}

	public void save(PmProjects transientInstance) {
		log.debug("saving PmProjects instance");
		try {
			getHibernateTemplate().saveOrUpdate(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(PmProjects persistentInstance) {
		log.debug("deleting PmProjects instance");
		try {
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public PmProjects findById(java.lang.Integer id) {
		log.debug("getting PmProjects instance with id: " + id);
		try {
			PmProjects instance = (PmProjects) getHibernateTemplate().get(
					"org.ss.psci.entity.PmProjects", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(PmProjects instance) {
		log.debug("finding PmProjects instance by example");
		try {
			List results = getHibernateTemplate().findByExample(instance);
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding PmProjects instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from PmProjects as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName1, Object value1,
			String propertyName2, Object value2) {
		log.debug("finding PmProjects instance with property: " + propertyName1
				+ ", value: " + value1);
		try {
			String queryString = "from PmProjects as model where model."
					+ propertyName1 + "= ? and model." + propertyName2 + "=?";
			return getHibernateTemplate().find(queryString, new Object[]{value1,value2});
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}
	public List findByName(Object name1,Object name2) {
		return findByProperty(NAME, name1,PROJECTID,name2);
	}
	public List findByNumber(Object number1,Object number2) {
		return findByProperty(NUMBER, number1,PROJECTID,number2);
	}
	public List findByManager(Object manager1,Object manager2) {
		return findByProperty(MANAGER, manager1,PROJECTID,manager2);
	}
	public List findByCompany(Object company1,Object company2) {
		return findByProperty(COMPANY, company1,PROJECTID,company2);
	}

	
	public List findByName(Object name) {
		return findByProperty(NAME, name);
	}

	public List findByCompany(Object company) {
		return findByProperty(COMPANY, company);
	}

	public List findByNumber(Object number) {
		return findByProperty(NUMBER, number);
	}

	public List findByStartTime(Object startTime) {
		return findByProperty(START_TIME, startTime);
	}

	public List findByEndTime(Object endTime) {
		return findByProperty(END_TIME, endTime);
	}

	public List findByPrice(Object price) {
		return findByProperty(PRICE, price);
	}

	public List findByCost(Object cost) {
		return findByProperty(COST, cost);
	}

	public List findByArea(Object area) {
		return findByProperty(AREA, area);
	}

	public List findByManager(Object manager) {
		return findByProperty(MANAGER, manager);
	}

	public List findByManageDep(Object manageDep) {
		return findByProperty(MANAGE_DEP, manageDep);
	}

	public List findByDesignDep(Object designDep) {
		return findByProperty(DESIGN_DEP, designDep);
	}

	public List findByControlDep(Object controlDep) {
		return findByProperty(CONTROL_DEP, controlDep);
	}

	public List findByProfit(Object profit) {
		return findByProperty(PROFIT, profit);
	}

	public List findByIntroduce(Object introduce) {
		return findByProperty(INTRODUCE, introduce);
	}

	public List findByRemarks(Object remarks) {
		return findByProperty(REMARKS, remarks);
	}

	public List findAll() {
		log.debug("finding all PmProjects instances");
		try {
			String queryString = "from PmProjects";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public PmProjects merge(PmProjects detachedInstance) {
		log.debug("merging PmProjects instance");
		try {
			PmProjects result = (PmProjects) getHibernateTemplate().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(PmProjects instance) {
		log.debug("attaching dirty PmProjects instance");
		try {
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(PmProjects instance) {
		log.debug("attaching clean PmProjects instance");
		try {
			getHibernateTemplate().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public static PmProjectsDAO getFromApplicationContext(ApplicationContext ctx) {
		return (PmProjectsDAO) ctx.getBean("PmProjectsDAO");
	}
}